#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class Solution:
    def __init__(self):
        pass

    def longest_unique_word(self, string_input):
        s = set()

        max_len = 0
        cur_len = 0
        left_idx = right_idx = 0

        while right_idx < len(string_input):
            right_c = string_input[right_idx]
            right_idx += 1
            if right_c not in s:
                s.add(right_c)
                cur_len += 1
                max_len = max(cur_len, max_len)
            else:
                # 找到第一个重复元素
                left_c = string_input[left_idx]
                while left_c != right_c:
                    s.remove(left_c)
                    left_idx += 1
                    cur_len -= 1
                    left_c = string_input[left_idx]

                # 去掉重复元素
                assert left_c == right_c
                assert string_input[left_idx] == string_input[right_idx-1]
                left_idx += 1

        return max_len



def test():
    input = "abcd####1234567"
    s = Solution()
    l = s.longest_unique_word(input)
    assert l == 8


def main():
    print("start main")

    test()

if __name__ == "__main__":
    main()
